﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbOrderDeliverDal
	{
		public DbOrderDeliverDal()
		{
		}
 		#region Insert
 		public static int Insert(DbOrderDeliver dbOrderDeliver)
		{	
			string sql = @"Insert Into DbOrderDeliver (
					DOrderSN,
					DName,
					DSN,
					DSendDate,
					DStatus
				) values('{0}','{1}','{2}','{3}',{4})";
			sql = string.Format(sql,
					SqlHelper.String(dbOrderDeliver.DOrderSN),
					SqlHelper.String(dbOrderDeliver.DName),
					SqlHelper.String(dbOrderDeliver.DSN),
					dbOrderDeliver.DSendDate,
					dbOrderDeliver.DStatus
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbOrderDeliver dbOrderDeliver)
		{	
			string sql = @"Update DbOrderDeliver set 

					DOrderSN= '{0}',
					DName= '{1}',
					DSN= '{2}',
					DSendDate= '{3}',
					DStatus= {4}
				where

					DId= {5}";
			sql = string.Format(sql,
					SqlHelper.String(dbOrderDeliver.DOrderSN),
					SqlHelper.String(dbOrderDeliver.DName),
					SqlHelper.String(dbOrderDeliver.DSN),
					dbOrderDeliver.DSendDate,
					dbOrderDeliver.DStatus,
					dbOrderDeliver.DId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 dId)
		{
		
			string sql = @"Delete from DbOrderDeliver where 
					DId= {0}";
			sql = string.Format(sql,
					dId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbOrderDeliver a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbOrderDeliver Select(Int32 dId)
		{
			DbOrderDeliver dbOrderDeliver = null;
			string sql = @"select a.* from DbOrderDeliver a  where
					a.DId= {0}
";
			sql = string.Format(sql,
					dId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbOrderDeliver = new DbOrderDeliver(ds.Tables[0].Rows[0]);					
			return dbOrderDeliver;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbOrderDeliver a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbOrderDeliver a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbOrderDeliver a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
